{#- 处理导入 -#}
import React, { Component } from 'react';
import { connect } from 'dva';
{% for from,imports in components.iteritems() -%}
import {{ '{ ' }}{%- for import in imports %}{{ import }}{%- if not loop.last -%}, {% endif -%}{% endfor %}{{ ' }' }} from '{{ from }}';
{% endfor %}
{% for import,from in components_brace_away.iteritems() -%}
import {{ import }} from '{{ from }}';
{% endfor %}
import PageEvent from './{{ page_name }}Event';
{% for component,consts in components_split_const.iteritems() %}
const {
  {% for const_name in consts %}{{const_name}}{%- if not loop.last -%},{% endif -%}{% endfor %}
} = {{component}};
{% endfor %}

class {{RootElement}} extends Component {å
  constructor (...props) {
    super(...props);
    this.state = PageEvent.state || {};
{%- for k in events %}
    this.{{events[k].func_name}} = this.{{events[k].func_name}}.bind(this);
{%- endfor %}
  }
{% for k in events %}
  {{events[k].func_name}} (...args){
    return PageEvent.{{events[k].func_name}}.call(this, ...args);
  }
{% endfor %}
{{'  '}}render () {
    return (
{%- for item in elements recursive %}
  {{ (loop.depth + 1) * '  ' }}{{- '<' }}{{ item.component.component }}
  {%- for attr in item.attrs -%}
    {%- if attr.type == 'props' -%}{{ ' ' }}{{ attr.k }}={{ '{this.props.'+ attr.v +'}' }}{%- endif -%}
    {%- if attr.type == 'text' -%}{{ ' ' }}{{ attr.k }}={{ '"' + attr.v + '"'}}{%- endif -%}
    {%- if attr.type == 'func' -%}{{ ' ' }}{{ attr.k }}={{ '{this.'+ attr.v + '}' }}{%- endif -%}
    {%- if attr.type == 'columns' -%}{{ ' ' }}{{ attr.k }}={{ attr.v }}{%- endif -%}
  {%- endfor-%}
  {%- if item.elements -%} >{{ loop(item.elements) }}
    {{ (loop.depth) * '  ' }}{{ '</' }} {{- item.component.component -}}>{%- elif item.m_text -%}>{{ item.m_text }}{{ '</' }} {{- item.component.component -}}{{ '>' -}}
  {% else %} />{%- endif %}
{%- endfor %}
    );
  }
}
{# 包装页面对象并导出 #}
{{ RootElement }}.propTypes = PageEvent.propTypes || {};
export default connect(...PageEvent.mergeProps)({{ RootElement }});

